<template>
	<div class="mallList">
		<el-form ref="form" :model="queryData" inline>
			<el-form-item>
				<el-select v-model="queryData.product_brand_id" filterable clearable placeholder="请选择商品品牌">
					<el-option v-for="(item,index) in brandListData" :key="index" :label="item.brandTitle"
						:value="item.id">
						<div style="display: flex;align-items: center;">
							<img :src="item.brandLogo" style="width: 20px;height: 20px;">
							<span class="ml5">{{item.brandTitle}}</span>
						</div>
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-input v-model="queryData.product_name" placeholder="商品名称" clearable style="width: 150px;">
				</el-input>
			</el-form-item>
			<el-form-item>
				<el-input v-model="queryData.product_code" placeholder="商品编码" clearable style="width: 170px;">
				</el-input>
			</el-form-item>
			<el-form-item>
				<el-cascader :show-all-levels="false" :props="categoryDataProps" v-model="categoryData"
					:options="categoryListData" placeholder="请选择商品分类" clearable></el-cascader>
			</el-form-item>
			<el-form-item>
				<el-select v-model="queryData.product_status" clearable placeholder="请选择审核状态" style="width: 160px;">
					<el-option label="编辑" value="0"></el-option>
					<el-option label="待审核" value="1"></el-option>
					<el-option label="审核通过" value="2"></el-option>
					<el-option label="审核不通过" value="3"></el-option>
					<el-option label="上架" value="4"></el-option>
					<el-option label="下架" value="5"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-select v-model="queryData.query_type" placeholder="请选择查询类型" style="width: 210px;">
					<el-option label="更新时间" value="0"></el-option>
					<el-option label="综合" value="1"></el-option>
					<el-option label="价格" value="2"></el-option>
					<el-option label="销量" value="3"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-select v-model="queryData.sort_type" placeholder="请选择排序方式" style="width: 210px;">
					<el-option label="正序" value="1"></el-option>
					<el-option label="倒序" value="2"></el-option>
				</el-select>
			</el-form-item>

			<el-form-item>
				<el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
				<!--  v-if="isUnlock" -->
				<el-button type="primary" icon="el-icon-plus" @click="addMall">添加商品</el-button>
				<el-button type="primary" icon="el-icon-key" @click="alldown">下架所有商品</el-button>
				<!-- <el-button type="primary" icon="el-icon-key" @click="unlock" v-else>解锁商品位</el-button> -->
			</el-form-item>
		</el-form>

		<el-table border :data="tableData" :row-class-name="tableRowClassName" style="width: 100%">
			<el-table-column prop="productMainImageUrl" label="商品主图" align="center" fixed width="120">
				<template slot-scope="scope">
					<el-image :src="scope.row.productMainImageUrl" style="width: 80px;"></el-image>
				</template>
			</el-table-column>
			<el-table-column prop="productStatus" label="状态 " align="center" width="120">
				<template slot-scope="scope">
					<el-tag>{{PRODUCTSTATUS[scope.row.productStatus]}}</el-tag>
				</template>
			</el-table-column>
			<el-table-column prop="lockStatus" label="锁定状态 " align="center" width="120">
				<template slot-scope="scope">
					<span>{{LOCKSTATUS[scope.row.lockStatus]}}</span>
				</template>
			</el-table-column>

			<el-table-column prop="verifyMsg" label="审核消息" align="center" width="150" show-overflow-tooltip>
			</el-table-column>

			<el-table-column prop="productBrandName" label="商品品牌" align="center" min-width="150" show-overflow-tooltip>
			</el-table-column>

			<el-table-column prop="productCode" label="商品编码" align="center" min-width="150" show-overflow-tooltip>
			</el-table-column>

			<el-table-column prop="productName" label="商品名称" align="center" min-width="150" show-overflow-tooltip>
			</el-table-column>

			<el-table-column prop="productTitle" label="商品副标题" align="center" min-width="150" show-overflow-tooltip>
			</el-table-column>
			<el-table-column prop="groups" label="所属分组" align="center" min-width="150" show-overflow-tooltip>
				<template slot-scope="scope">
					{{changeFenZu(scope.row.groups)}}
				</template>
			</el-table-column>

			<el-table-column prop="productCategoryName" label="所属分类" align="center" min-width="150"></el-table-column>

			<el-table-column prop="topCategoryName" label="一级分类" align="center" min-width="150"></el-table-column>

			<el-table-column prop="productSalePrice" label="商品销售价格" align="center" width="120">
			</el-table-column>

			<el-table-column prop="salePrice" label="商品出售价格(抵扣后价格)" align="center" width="120"></el-table-column>

			<el-table-column prop="sweetDeductRate" label="商品糖果抵扣率(%)" align="center" width="120"></el-table-column>

			<el-table-column prop="saleSweet" label="商品出售糖果数" align="center" width="150">
			</el-table-column>
			<el-table-column prop="productType" label="商品类型" align="center" width="150">
				<template slot-scope="scope">
					<span>{{scope.row.productType==1?'实物商品':'虚拟商品'}}</span>
				</template>
			</el-table-column>

			<el-table-column prop="totalStocks" label="商品总库存" align="center" width="150">
			</el-table-column>
			<el-table-column prop="soldUnit" label="商品销量" align="center" width="150">
			</el-table-column>

			<el-table-column prop="createDate" label="创建时间" align="center" width="170">
			</el-table-column>

			<el-table-column label="操作" align="center" width="320" fixed="right">
				<template slot-scope="scope">
					<el-button v-if="scope.row.lockStatus == 1" type="text" icon="el-icon-lock" @click="openLock">解锁
					</el-button>
					<div v-else>
						<el-button type="primary" size="mini" icon="el-icon-edit" @click="mallUpdate(scope.row)"
							v-show="scope.row.productStatus==2||scope.row.productStatus==1||scope.row.productStatus==3||scope.row.productStatus==0||scope.row.productStatus==5||scope.row.productStatus==4">
							{{scope.row.productStatus==4?'查看':'编辑'}}
						</el-button>
						<el-button type="primary" size="mini" icon="el-icon-edit"
							v-show="scope.row.productStatus==0||scope.row.productStatus==3" @click="fabu(scope.row)">发布
						</el-button>
						<el-button type="primary" size="mini" @click="chexiao(scope.row)"
							v-show="scope.row.productStatus==1">撤销</el-button>
						<el-button
							:type="scope.row.productStatus==4?'success':scope.row.productStatus==2?'success':scope.row.productStatus==5?'warning':''"
							size="mini" @click="xiajia(scope.row)"
							v-show="scope.row.productStatus==4||scope.row.productStatus==5||scope.row.productStatus==2">
							{{scope.row.productStatus==4?'下架':scope.row.productStatus==2?"下架":scope.row.productStatus==5?'上架':''}}
						</el-button>
						<el-button type="danger" size="mini" @click="mallDelete(scope.row)">删除</el-button>
					</div>
				</template>
			</el-table-column>
		</el-table>

		<div class="pages">
			<el-pagination :page-size="queryData.size" :current-page="queryData.page"
				layout="prev, pager, next,total,jumper" :total="total" background @current-change="handleCurrentChange">
			</el-pagination>
		</div>

		<el-dialog title="审核" :visible.sync="verify" width="500px">
			<el-form ref="form" :model="verifyForm" label-width="80px">
				<el-form-item label="审核状态">
					<el-select v-model="verifyForm.verifyStatus" placeholder="请选择审核状态">
						<el-option label="审核通过" value="2"></el-option>
						<el-option label="审核不通过" value="3"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="备注" v-show="verifyForm.verifyStatus == 3">
					<el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="verifyForm.verifyMsg"
						style="width: 240px;">
					</el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit">确定</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>

		<el-dialog :title="title" :visible.sync="mallVisible" width="100%" :close-on-click-modal="false">
			<el-tabs type="card" v-model="activeName" @tab-click="tabHandleClick">
				<el-tab-pane label="商品基本信息" name="1">
					<el-card class="box-card">
						<div slot="header" class="clearfix"><span>基本信息</span></div>
						<el-form ref="form" :model="form" label-width="130px" size="small" :rules="rules">
							<el-form-item label="商品类型">
								<el-radio-group v-model="form.productType" @change="radioChange">
									<el-radio-button label="1" border>实物商品</el-radio-button>
								</el-radio-group>
							</el-form-item>

							<el-row :gutter="20">
								<el-col :span="8">
									<el-form-item label="商家" prop="mid">
										<el-select disabled v-model="form.mid" filterable clearable placeholder="请选择"
											@change="mechantChange">
											<el-option v-for="(item,index) in restaurants" :key="index"
												:label="item.namePhone" :value="item.mid">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
								<el-col :span="8">
									<el-form-item label="商品类目" prop="productCategoryId">
										<div style="display: flex;">
											<el-input disabled v-model="form.productCategoryName"></el-input>
											<el-button icon="el-icon-search" type="primary" class="ml0"
												@click="chazhao">查找</el-button>
										</div>
									</el-form-item>
								</el-col>
								<el-col :span="8">
									<el-form-item label="商品品牌" prop="productBrandId">
										<el-select v-model="form.productBrandId" filterable clearable placeholder="请选择">
											<el-option v-for="(item,index) in brandListData" :key="index"
												:label="item.brandTitle" :value="item.id">
												<div style="display: flex;align-items: center;">
													<img :src="item.brandLogo" style="width: 20px;height: 20px;">
													<span class="ml5">{{item.brandTitle}}</span>
												</div>
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
							</el-row>

							<el-row :gutter="20">
								<el-col :span="8">
									<el-form-item label="商品名称" prop="productName">
										<el-input v-model="form.productName" placeholder="请输入商品名称"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="8">
									<el-form-item label="副标题" prop="productTitle">
										<el-input v-model="form.productTitle" placeholder="请输入商品副标题"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="8">
									<el-form-item label="商品类别" prop="type">
										<el-select v-model="form.type" placeholder="请选择">
											<el-option label="普通商品" :value="0"></el-option>
											<el-option label="文娱充值" :value="1"></el-option>
											<el-option label="话费充值" :value="2"></el-option>
										</el-select>
									</el-form-item>
								</el-col>
							</el-row>
							<el-row :gutter="20">
								<el-col :span="8">
									<el-form-item label="限购数量" prop="limitNum">
										<el-input-number v-model="form.limitNum" :min="0" label="请输入商品限购数量">
										</el-input-number>
									</el-form-item>
								</el-col>
								<el-col :span="8">
									<el-form-item label="限购次数" prop="limitTimes">
										<el-input-number v-model="form.limitTimes" :min="0" label="请输入商品限购次数">
										</el-input-number>
									</el-form-item>
								</el-col>
								<el-col :span="8">
									<el-form-item label="商品订单过期时间" prop="expireTime">
										<el-input-number v-model="form.expireTime" :min="30" label="请输入商品订单过期时间">
										</el-input-number>
										<span class="ml0">分钟</span>
									</el-form-item>
								</el-col>
							</el-row>
							<el-form-item>
								<span style="color: red;">*若进行限购 请在副标题或兑换须知中明确说明</span>
							</el-form-item>

							<el-form-item label="兑换须知" prop="productDesc">
								<el-input v-model="form.productDesc" type="textarea" :rows="4" placeholder="请输入兑换须知">
								</el-input>
								<span
									style="color: red;font-size: 13px;">*此处需填：下单付款后的发货时间、不发货地区、不包邮地区等买家需要注意的购买事项</span>
							</el-form-item>
							<el-row :gutter="20">
								<el-col :span="8">
									<el-form-item label="销售价格" prop="productSalePrice">
										<el-input v-model="form.productSalePrice" placeholder="请输入商品销售价格"
											@input="productSalePriceChange"></el-input>
									</el-form-item>
								</el-col>
								<el-col :span="8">
									<el-form-item label="成本价格" prop="productCostPrice">
										<el-input v-model="form.productCostPrice" placeholder="请输入商品成本价格"></el-input>
									</el-form-item>
								</el-col>
							</el-row>
							<el-row v-show="form.productSalePrice">
								<el-col :span="24">
									<el-form-item label="糖果抵扣率" prop="sweetDeductRate">
										<el-slider v-model="form.sweetDeductRate" :max="mallDeductRate" show-input
											@change="sweetDeductRateChange"></el-slider>
										<span>当天实时参考价格:<span
												style="color: red;font-size: 14px;padding-left: 5px;">¥{{cankaoPrice.salePrice}}</span>
											+ <span
												style="color: red;font-size: 14px;">{{cankaoPrice.saleSweet}}</span>个糖果</span>
									</el-form-item>
								</el-col>
							</el-row>
							<el-row>
								<el-col :span="8">
									<el-form-item label="预警数量" prop="warnUnit">
										<el-input v-model="form.warnUnit" placeholder="预警数量" style="width: 120px;">
										</el-input>
									</el-form-item>
								</el-col>
								<el-col :span="8">
									<el-form-item label="重量(kg)" v-show="form.productType==1" prop="productWeight">
										<el-input-number v-model="form.productWeight" controls-position="right"
											:min="0"></el-input-number>
										<el-tooltip content="用于按重量计算运费" placement="top-start" class="ml0">
											<span style="cursor: pointer;">?</span>
										</el-tooltip>
									</el-form-item>
								</el-col>
							</el-row>

							<el-form-item label="是否使用优惠券" prop="isUseCoupon">
								<el-radio-group v-model="form.isUseCoupon">
									<el-radio :label="true">是</el-radio>
									<el-radio :label="false">否</el-radio>
								</el-radio-group>
							</el-form-item>
							
							<el-form-item label="是否使用金豆抵扣" prop="goldenBeansStatus">
							  <el-radio-group v-model="form.goldenBeansStatus">
							    <el-radio :label="1">是</el-radio>
							    <el-radio :label="0">否</el-radio>
							  </el-radio-group>
							</el-form-item>
							
							<el-form-item v-if="form.goldenBeansStatus">
							  <span style="font-size: 14px;">
                  当天实时金豆抵扣参考价格为:
                  <span style="color: red;">
                    {{goldenBeanPrice}}
                    <span style="padding-left: 5px;">
                     [ {{goldNumber}}颗金豆可抵扣{{form.productSalePrice}} ]
                    </span>
                  </span>
                </span>
							</el-form-item>
							
							<el-row :gutter="20" v-show="form.productType==1">
								<el-col :span="8">
									<el-form-item label="配送方式" prop="isDeliveryExpressEnabled">
										<el-checkbox v-model="form.isDeliveryExpressEnabled">快递配送</el-checkbox>
									</el-form-item>
									<el-form-item prop="isDeliveryPickEnabled">
										<el-checkbox v-model="form.isDeliveryPickEnabled">门店自提(自提点为商家地址)</el-checkbox>
									</el-form-item>
								</el-col>
								<el-col :span="8">
									<el-form-item label="运费模板" v-show="form.isDeliveryExpressEnabled"
										prop="productFreightId">
										<el-select v-model="form.productFreightId" filterable clearable
											placeholder="请选择">
											<el-option v-for="(item,index) in shippingData" :key="index"
												:label="item.transName" :value="item.transportId">
											</el-option>
										</el-select>
									</el-form-item>
								</el-col>
							</el-row>
							<el-form-item class="mt10">
								<el-button type="primary" @click="submit('form')">保存</el-button>
							</el-form-item>
						</el-form>
					</el-card>
				</el-tab-pane>

				<el-tab-pane label="商品图片" :disabled="progress<1" name="2">
					<el-card class="box-card mt10 product-card">
						<div slot="header" class="clearfix"><span>商品Banner图片[首张用于商品封面]</span></div>
						<div>
							<el-button type="primary" size="small" style="margin-bottom:10px" @click="isSort=!isSort">
								图片排序</el-button>
						</div>
						<el-upload :action="action" :on-remove="handleRemove" :before-remove="beforeRemove" name="image"
							:headers="headers" :data="uploadData" ref="upLoad" :auto-upload="true"
							:before-upload='beforeUpload' list-type="picture-card" :file-list="fileList"
							:on-success="handleSuccess">
							<i class="el-icon-plus"></i>
							<div slot="file" slot-scope="{file}">
								<div
									style="position:relative;width:148px;height:148px;border-radius:6px;overflow: hidden;">
									<img class="el-upload-list__item-thumbnail" :src="file.url" alt="">
									<span class="el-upload-list__item-actions">
										<span class="el-upload-list__item-preview"
											@click="handlePictureCardPreview(file)">
											<i class="el-icon-zoom-in"></i>
										</span>
										<span v-if="!disabled" class="el-upload-list__item-delete"
											@click="handleDownload(file)">
											<i class="el-icon-download"></i>
										</span>
										<span v-if="!disabled" class="el-upload-list__item-delete"
											@click="handleRemove(file)">
											<i class="el-icon-delete"></i>
										</span>
									</span>
								</div>
								<div style="text-align: center;padding-top: 10px;" v-show="isSort">
									<el-input-number v-model="file.sort" @change="changeCardSort($event, file)"
										size="mini"></el-input-number>
								</div>
							</div>
						</el-upload>
						<div style="margin-bottom:15px">
							<el-link type="danger" :underline="false">* 1、图片必须清晰；2、图片尺寸必须为720*720 PX; 3、主图上传的数量必须为
								4至6张；4、图片的质量必须达到标准（
								可参照淘宝天猫的商品主图，不能直接用自己拍照后没经修饰的图片 ）以上任何一条要求没达到，便会审核不通过。</el-link>
						</div>
						<el-button v-show="isSort" type="primary" size="small" style="margin-bottom:10px"
							@click="submitCardSort">确认排序</el-button>
					</el-card>

					<el-card class="box-card mt10">
						<div slot="header" class="clearfix">
							<span style="margin-right: 40px;">商品详情图</span>
							<el-link type="danger" :underline="false">*1、详情图必须清晰；2、详情图不能太短，要能体现商品的主要卖点；3、详情图的质量必须达到标准（
								具体可参照淘宝天猫的商品详情图，不能直接用自己拍照后没经修饰的图片 ）；4、上传的详情页内容（比如文字、图片等信息）必须全部靠左对齐；
								5.详情图必须控制在2M以内；以上任何一条要求没达到，便会审核不通过。</el-link>

						</div>
						<editor :catchData='catchData' :text="details" ref="editor" :product_id="productId" />
					</el-card>

					<div class="mt10">
						<el-button type="primary" @click="ImgSubmit()">保存</el-button>
					</div>
				</el-tab-pane>

				<el-tab-pane label="商品参数" :disabled="progress<2" name="3">
					<el-form :model="ParameterFrom">
						<el-form-item v-for="(item, index) in ParameterFrom.parameter" :key="index">
							<el-row :gutter="20">
								<el-col :span="4">
									<el-input v-model="item.productAttrName" placeholder="参数名" clearable></el-input>
								</el-col>
								<el-col :span="8">
									<el-input v-model="item.productAttrValue" placeholder="参数值" clearable></el-input>
								</el-col>
								<el-col :span="12">
									<el-button @click.prevent="removeParameter(item)">删除</el-button>
								</el-col>
							</el-row>
						</el-form-item>
					</el-form>
					<div style="margin-bottom:15px">
						<el-link type="danger" :underline="false">* 商品参数是用于描述商品的属性。例如手机核数、版本等额外信息</el-link>
					</div>
					<el-button type="primary" icon="el-icon-plus" @click="addParameter">添加参数</el-button>
					<el-button type="primary" @click="ParameterSubmit">保存</el-button>
				</el-tab-pane>

				<el-tab-pane label="规格库存" :disabled="progress<3" name="4">
					<el-form :model="skuData" label-width="120px" size="small" v-if="this.title=='添加商品'">
						<div v-for="(item,index) in skuData.skuSpecAndDetailDTOS" :key="index">
							<el-form-item label="规格名" :prop="'skuSpecAndDetailDTOS.' + index + '.specName'"
								:rules="{required: true, message: '规格名不能为空', trigger: 'blur'}">
								<el-input v-model="item.specName" placeholder="规格名" style="width: 120px;"></el-input>
								<el-button type="text" style="margin-left: 10px;" @click="skuDelete(index)">删除规格
								</el-button>
							</el-form-item>

							<el-form-item label="规格值">
								<el-input v-for="(specDetail,index2) in item.specDetails" :key="index2"
									v-model="specDetail.specDetailName" placeholder="规格值"
									style="width: 120px;margin-right: 10px;">
									<i slot="suffix" class="el-input__icon el-icon-delete"
										@click="iconDelete(index,index2)"></i>
								</el-input>
								<el-button type="text" style="margin: 0px 10px;" @click="addSpecDetail(index)">添加规格值
								</el-button>
							</el-form-item>
						</div>

						<el-form-item>
							<el-button type="primary" icon="el-icon-plus" @click="addSku">添加规格项目</el-button>
							<el-button type="primary" icon="el-icon-check" @click="skuSubmit()">确定</el-button>
						</el-form-item>
					</el-form>

					<div style="margin-bottom: 15px;" v-else>
						<el-button type="primary" size="small" @click="addSpecs()">添加规格</el-button>
						<el-button type="primary" size="small" @click="addStock()">添加SKU</el-button>
					</div>

					<el-table :data="SkuTableData" style="width: 100%" border v-if="this.title=='添加商品'">
						<el-table-column v-for="(item,index) in tableHead" :key="index" :label="item.label"
							:prop="item.property" align="center" fixed="left">
							<template slot-scope="scope">{{scope.row[scope.column.property]}}</template>
						</el-table-column>

						<el-table-column prop="skuName" label="名称" align="center" width="160">
							<template slot-scope="scope">
								<el-input v-model="scope.row.skuName" size="mini" :disabled='scope.row.disabled'
									clearable></el-input>
							</template>
						</el-table-column>
						<el-table-column prop="extId" label="虚拟商品的ID" align="center" width="160"
							v-if="form.productType==2">
							<template slot-scope="scope">
								<el-input v-model="scope.row.extId" size="mini" :disabled='scope.row.disabled'
									clearable></el-input>
							</template>
						</el-table-column>

						<el-table-column prop="limitNum" label="数量限制" align="center" width="160"
							v-if="form.productType==2">
							<template slot-scope="scope">
								<el-input v-model="scope.row.limitNum" size="mini" :disabled='scope.row.disabled'
									clearable></el-input>
							</template>
						</el-table-column>

						<el-table-column prop="skuSalePrice" label="销售价" align="center" width="160">
							<template slot-scope="scope">
								<el-input v-model="scope.row.skuSalePrice" size="mini" :disabled='scope.row.disabled'
									clearable @blur="skuSweetDeductPriceChange(scope.$index,scope.row)"></el-input>
							</template>
						</el-table-column>
						<el-table-column prop="skuSweetDeductRate" label="糖果抵扣率" align="center" width="300">
							<template slot-scope="scope">
								<el-slider :disabled='scope.row.disabled' v-model="scope.row.skuSweetDeductRate"
									:max="mallDeductRate" show-input
									@change="skuSweetDeductPriceChange(scope.$index,scope.row)"></el-slider>
								<span>当天实时参考价格:<span
										style="color: red;font-size: 14px;padding-left: 5px;">¥{{scope.row.salePrice}}</span>
									+ <span style="color: red;font-size: 14px;">{{scope.row.saleSweet}}</span>个糖果</span>
							</template>
						</el-table-column>

						<el-table-column prop="skuCostPrice" label="成本价" align="center" width="160">
							<template slot-scope="scope">
								<el-input v-model="scope.row.skuCostPrice" size="mini" :disabled='scope.row.disabled'
									clearable></el-input>
							</template>
						</el-table-column>
						<el-table-column prop="skuTotalStocks" label="库存" align="center" width="160">
							<template slot-scope="scope">
								<el-input v-model="scope.row.skuTotalStocks" size="mini" :disabled='scope.row.disabled'
									clearable></el-input>
							</template>
						</el-table-column>
						<el-table-column prop="skuWarnUnit" label="库存预警数量" align="center" width="160">
							<template slot-scope="scope">
								<el-input v-model="scope.row.skuWarnUnit" size="mini" :disabled='scope.row.disabled'
									clearable></el-input>
							</template>
						</el-table-column>
						<el-table-column prop="skuPicUrl" label="图片(点击上传)" align="center" width="160">
							<template slot-scope="scope">
								<el-image :src="scope.row.skuPicUrl" :disabled='scope.row.disabled'
									@click.native="addSkuImage(scope.$index, SkuTableData)"
									style="width: 60px; height: 60px"></el-image>
							</template>
						</el-table-column>
						<el-table-column label="操作" align="center" fixed="right" width="160">
							<template slot-scope="scope">
								<el-button type="primary" v-show="title=='编辑商品'" size="small"
									@click="skubianji(scope.$index,scope.row)">{{scope.row.disabled?'编辑':'保存'}}
								</el-button>
								<el-button type="danger" @click="removeSku(scope.$index,scope.row)" size="small">删除
								</el-button>
							</template>
						</el-table-column>
					</el-table>

					<div v-else>
						<el-table :data="skusData" style="width:100%;" :row-class-name="tableRowClassName2" border>
							<el-table-column prop="propertiesValue" label="规格" align="center" width="160">
							</el-table-column>
							<el-table-column prop="skuCode" label="编码" align="center" width="180">
							</el-table-column>
							<el-table-column prop="skuName" label="名称" align="center" width="160">
							</el-table-column>
							<el-table-column prop="extId" label="虚拟商品的ID" align="center" width="160"
								v-if="form.productType==2">
							</el-table-column>
							<el-table-column prop="limitNum" label="数量限制" align="center" width="160"
								v-if="form.productType==2">
							</el-table-column>
							<el-table-column prop="skuSalePrice" label="销售价" align="center" width="160">
							</el-table-column>
							<el-table-column prop="skuSweetDeductRate" label="糖果抵扣率(%)" align="center" width="320">
								<template slot-scope="scope">
									<span>{{scope.row.skuSweetDeductRate}}</span>
									<br />
									<span style="font-size: 12px;">当天实时参考价格:
										<span
											style="color: red;font-size: 14px;padding-left: 5px;">¥&nbsp;{{scope.row.salePrice}}</span>
										+ <span style="color: red;font-size: 14px;">
											<i class="el-icon-sugar"></i>
											{{scope.row.saleSweet}}
										</span>个糖果</span>
								</template>
							</el-table-column>
							<el-table-column prop="skuCostPrice" label="成本价" align="center" width="160">
							</el-table-column>
							<el-table-column prop="skuTotalStocks" label="库存" align="center" width="160">
								<template slot-scope="scope">
									<el-button type="text" @click="viewStocks(scope.row)">{{scope.row.skuTotalStocks}}
									</el-button>
								</template>
							</el-table-column>
							<el-table-column prop="skuWarnUnit" label="库存预警数量" align="center" width="160">
							</el-table-column>
							<el-table-column prop="skuPicUrl" label="图片" align="center" width="160">
								<template slot-scope="scope">
									<el-image :src="scope.row.skuPicUrl" style="width: 60px; height: 60px"></el-image>
								</template>
							</el-table-column>
							<el-table-column label="操作" align="center" fixed="right" width="160">
								<template slot-scope="scope">
									<el-button type="primary" size="small" @click="addStock(scope.row)">编辑</el-button>
									<el-button type="danger" @click="deleteSku(scope.$index,scope.row)" size="small">删除
									</el-button>
								</template>
							</el-table-column>
						</el-table>

						<div class="pages">
							<el-pagination :page-size="skuSize" :current-page="skuPage"
								layout="prev, pager, next,total,jumper" :total="skuTotal" background
								@current-change="skuHandleCurrentChange">
							</el-pagination>
						</div>
					</div>

					<div style="margin:15px 0">
						<el-button v-show="title == '添加商品'" type="primary" @click="baocunSku">保存规格</el-button>
					</div>
				</el-tab-pane>
			</el-tabs>
		</el-dialog>

		<el-dialog title="选择商品品类" :visible.sync="leimuVisible" width="500px" custom-class="custom-class">
			<div class="Category">
				<el-tree :data="category" :default-expanded-keys="keys" :expand-on-click-node="false" node-key="id"
					:props="defaultProps">
					<span class="custom" slot-scope="{ node, data }">
						<div>
							<span>{{ node.label }}</span>
						</div>
						<div>
							<el-button v-show="data.parentId != 0" size="mini" icon="el-icon-plus"
								@click="choice(node, data)">选择类目</el-button>
						</div>
					</span>
				</el-tree>
			</div>
		</el-dialog>

		<el-dialog title="上传规格图片" :visible.sync="guigeVisible" width="500px" custom-class="custom-class">
			<el-upload :action="action2" :headers="headers" :file-list="SKufileList" :data="skuImgupload" name="image"
				list-type="picture-card" :limit="1" :before-upload='beforeUpload' :on-success="skuSuccessHandle">
				<i slot="default" class="el-icon-plus"></i>
				<div slot="file" slot-scope="{file}">
					<img class="el-upload-list__item-thumbnail" :src="file.url" alt="">
					<span class="el-upload-list__item-actions">
						<span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
							<i class="el-icon-zoom-in"></i>
						</span>
						<span class="el-upload-list__item-delete" @click="SkuHandleRemove()">
							<i class="el-icon-delete"></i>
						</span>
					</span>
				</div>
			</el-upload>
			<div style="margin:15px 0;">
				<el-link type="danger" :underline="false">* 图片尺寸规格必须为720*720，图片背景要求非白色，左上角不能放文字/logo，否则审核不通过</el-link>
			</div>
		</el-dialog>

		<el-dialog :visible.sync="dialogVisible">
			<img width="100%" :src="dialogImageUrl" alt="">
		</el-dialog>

		<el-dialog title="查看分组" :visible.sync="fenzudialogVisible">
			<div style="display: flex;align-items: center;justify-content: center;">
				<el-transfer v-model="fenzu" :data="fenZuData" :titles="['分组列表', '已分组列表']"></el-transfer>
			</div>
			<div style="display: flex;justify-content: center;margin-top: 30px;">
				<el-button type="primary" size="medium" @click="fenZuSubmit()">确定</el-button>
			</div>
		</el-dialog>

		<el-dialog title="规格" :visible.sync="dialogSpecs" width="50%">
			<el-form :inline="true" :model="guigeFormData">
				<el-form-item>
					<el-input type="text" placeholder="请输入规格" prop="guige" v-model="guigeFormData.guige"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="addguige">确定</el-button>
				</el-form-item>
			</el-form>
			<el-tree :data="guigeData" :props="guigedefaultProps" node-key="id" :expand-on-click-node="false">
				<span class="custom-tree-node" slot-scope="{ node, data }">
					<span>{{ node.label }}</span>
					<span>
						<el-button type="text" size="mini" @click="() => append(data)" v-show="data.specDetails">添加
						</el-button>
						<el-button type="text" size="mini" @click="() => modify(node, data)">修改</el-button>
						<el-button type="text" size="mini" @click="() => remove(node, data)">删除</el-button>
					</span>
				</span>
			</el-tree>
		</el-dialog>

		<el-dialog title="SKU" :visible.sync="dialogStock" width="50%">
			<el-form ref="stockData" :model="stockData" label-width="140px">

				<el-form-item :label="item.specName" v-for="item in guigeData" :key="item.id" required v-if="skuActive">
					<el-select :placeholder="'请选择'+item.specName" v-model="stockData.specDetailMap[item.id]"
						@change="skuChange($event,item.specName)">
						<el-option :label="item2.specDetailName" :value="item2.id" v-for="item2 in item.specDetails"
							:key="item2.id"></el-option>
					</el-select>
				</el-form-item>

				<el-form-item label="规格" v-else>
					<span>{{stockData.propertiesValue}}</span>
				</el-form-item>

				<el-form-item label="名称" required>
					<el-input v-model="stockData.skuName"></el-input>
				</el-form-item>
				<el-form-item label="额外虚拟商品的ID" required v-if="form.productType==2">
					<el-input v-model="stockData.extId"></el-input>
				</el-form-item>

				<el-form-item label="数量限制" required v-if="form.productType==2">
					<el-input v-model="stockData.limitNum"></el-input>
				</el-form-item>
				<el-form-item label="销售价" required>
					<el-input v-model="stockData.skuSalePrice" @blur="sweetChange"></el-input>
				</el-form-item>
				<el-form-item label="糖果抵扣率" required>
					<el-slider v-model="stockData.skuSweetDeductRate" :max="mallDeductRate" show-input
						@change="sweetChange()" style="margin-left: 15px;"></el-slider>
					<span>当天实时参考价格:<span
							style="color: red;font-size: 14px;padding-left: 5px;">¥{{skuSweetDeductRateData.salePrice}}</span>
						+ <span
							style="color: red;font-size: 14px;">{{skuSweetDeductRateData.saleSweet}}</span>个糖果</span>
				</el-form-item>
				<el-form-item label="成本价" required>
					<el-input v-model="stockData.skuCostPrice"></el-input>
				</el-form-item>
				<el-form-item label="库存" required>
					<el-input v-model="stockData.skuTotalStocks"></el-input>
				</el-form-item>
				<el-form-item label="库存预警数量" required>
					<el-input v-model="stockData.skuWarnUnit"></el-input>
				</el-form-item>
				<el-form-item label="sku图片" required>
					<el-image :src="stockData.skuPicUrl" @click.native="addSkuImages(SkuTableData)"
						style="width: 60px; height: 60px"></el-image>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="submitStock()">提交</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>

		<el-dialog :visible.sync="stockDialogVisible" width="80%">
			<el-tabs v-model="stockActiveName" type="card" @tab-click="stockHandleClick">
				<el-tab-pane label="库存变更日志" name="first">
					<el-table :data="stockChangeData" border stripe>
						<el-table-column prop="typeNo" label="变更业务编号/ID" align="center">
						</el-table-column>
						<el-table-column prop="num" label="变更数量" align="center"></el-table-column>
						<el-table-column prop="type" label="库存变更业务类型" align="center">
							<template slot-scope="scope">
								<span>{{scope.row.type==1?'商品购买扣减':scope.row.type==2?'购物车商品结算扣减':'售后处理变更'}}</span>
							</template>
						</el-table-column>
						<el-table-column prop="desc" label="变更说明" align="center"></el-table-column>
						<el-table-column prop="createDate" label="变更时间" align="center"></el-table-column>
					</el-table>

					<div class="pages">
						<el-pagination :page-size="stockSize" :current-page="stockPage"
							layout="prev, pager, next,total,jumper" :total="stockTotal" background
							@current-change="StockHandleCurrentChange">
						</el-pagination>
					</div>
				</el-tab-pane>
				<el-tab-pane label="库存变更记录" name="second">
					<el-table :data="stockChangeData" border stripe>
						<el-table-column prop="id" label="记录ID" align="center">
						</el-table-column>
						<el-table-column prop="num" label="变更数量" align="center"></el-table-column>
						<el-table-column prop="createDate" label="变更时间" align="center"></el-table-column>
					</el-table>

					<div class="pages">
						<el-pagination :page-size="stockSize" :current-page="stockPage"
							layout="prev, pager, next,total,jumper" :total="stockTotal" background
							@current-change="StockHandleCurrentChange">
						</el-pagination>
					</div>
				</el-tab-pane>
			</el-tabs>
		</el-dialog>


		<el-dialog title="解锁商品位" :visible.sync="lockVisible">
			<el-form :model="mallposition" :rules="mallpositionrules" ref="mallposition" label-width="100px">
				<el-form-item label="购买数量" prop="num">
					<el-input-number v-model="mallposition.num" :precision="0" :step="1" :min="1" label="描述文字">
					</el-input-number>
				</el-form-item>
				<el-form-item label="交易密码" prop="password">
					<el-input type="password" v-model="mallposition.password" placeholder="请输入交易密码"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="unlockMallPosition('mallposition')">立即解锁</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>
	</div>
</template>

<script>
	import editor from '@/components/editor2.vue'
	export default {
		data() {
			return {
				PRODUCTSTATUS: {
					0: '编辑',
					1: '待审核',
					2: '审核通过',
					3: '审核不通过',
					4: '上架',
					5: '下架',
					6: '删除'
				},
				LOCKSTATUS: {
					0: '开放',
					1: '锁定'
				},
				isSort: false,
				disabled: false,
				stockActiveName: 'first',
				stockDialogVisible: false,
				stockChangeData: [],
				stockProductId: '',
				stockSkuId: '',
				stockPage: 1,
				stockSize: 10,
				stockTotal: 0,
				//添加规格
				dialogSpecs: false,
				goodsId: '',
				guigeData: [],
				guigeFormData: {
					guige: '',
					guigeDetail: ''
				},
				guigedefaultProps: {
					id: 'id',
					children: 'specDetails',
					label: function(a, b) {
						return a.specName || a.specDetailName
					}
				},
				//添加库存
				skuSweetDeductRateData: {
					salePrice: 0,
					saleSweet: 0,
					mallDeductRates: 40
				},
				mallDeductRates: 40,
				skuActive: true,
				SkuDetails: false,
				dialogStock: false,
				skuId: '',
				stockData: {
					specDetailMap: {},
					skuName: '',
					extId: '',
					limitNum: '',
					skuOriginalPrice: '',
					skuSalePrice: '',
					skuSweetDeductRate: 0,
					skuCostPrice: '',
					skuTotalStocks: '',
					skuWarnUnit: '',
					skuPicUrl: ''
				},
				updateId: '',
				skuspecDetailIds: '',
				skuspecDetailName: '',
				stockArr: {},
				specDetailIds: [],
				skuguige: '',
				skuPicUrlList: [],

				fenzudialogVisible: false,
				fenzu: [],
				fenZuData: [],
				mallInfo: false,
				mallImage: true,
				mallParameter: true,
				mallSkue: true,
				activeName: '1',
				queryData: {
					size: 10,
					page: 1,
					mid: localStorage.getItem('merchantId'), //商家ID
					product_category_id: '', //商品分类ID
					product_name: '', //商品名称
					product_code: '', //商品编码
					sort_type: '2', //排序
					query_type: '0', //查询类型
					secondary_category_id: '', //二级分类id，不传则查询全部一级分类下的商品
					top_category_id: '', //一级分类id
					product_brand_id: '', //品牌ID
					product_status: '', //审核状态：-1 全部 0待审核，1审核通过，2审核未通过
					product_type: '1', //商品类型：1实物商品，2虚拟商品
				},
				total: 0,
				tableData: [],
				verify: false,
				verifyForm: {
					id: '',
					verifyStatus: '',
					verifyMsg: ''
				},
				title: '',
				mallVisible: false,
				restaurants: [], //商家列表
				brandListData: [], //品牌列表
				SameCityDeliveryData: [], //同城配送模版列表
				shippingData: [], //运费模版列表
				deliveryMethodID: [],
				leimuVisible: false,
				category: [{
					id: 0,
					parentId: 0,
					name: '全部类目',
					childList: []
				}],
				defaultProps: {
					children: 'childList',
					label: 'name'
				},
				keys: [],
				active: 0,
				cankaoPrice: {
					salePrice: 0,
					saleSweet: 0
				},
				form: {
					productType: 1, //商品类型
					createUserId: '', //用户ID
					mid: '', //商家id
					expireTime: '', //商品订单过期时间(单位:分钟)
					productCategoryName: '',
					isDeliveryCityEnabled: false, //同城配送
					isDeliveryExpressEnabled: false, //快递配送
					isDeliveryPickEnabled: false, //到店自提
					productBrandId: '', //商品品牌id
					productCategoryId: '', //商品类目id
					type: 0, //0-普通订单，3-新手免单
					productCostPrice: '', //商品成本价
					productDeliveryId: '', //同城配送模版id
					productDesc: '', //兑换须知
					productFreightId: '', //运费模板id
					productName: '', //商品名称
					productSalePrice: '', //商品销售价
					productTitle: '', //商品副标题
					productWeight: 0, //商品重量
					sweetDeductRate: 0, //糖果抵扣率
					warnUnit: '', //预警数量
					limitNum: 0, //限购数量
					limitTimes: 0, //限购次数
					isUseCoupon: true, //是否可使用优惠券购买
					goldenBeansStatus:1
				},
				progress: 0,
				rules: {
					mid: [{
						required: true,
						message: '请选择商家',
						trigger: 'change'
					}],
					productCategoryId: [{
						required: true,
						message: '请选择商品类目',
						trigger: 'change'
					}],
					productBrandId: [{
						required: true,
						message: '请选择商品品牌',
						trigger: 'change'
					}],
					productName: [{
						required: true,
						message: '请输入商品名称',
						trigger: 'blur'
					}],
					productSalePrice: [{
						required: true,
						message: '请输入销售价',
						trigger: 'blur'
					}]
				},
				productId: '',
				action: '/wsj/' + this.$api.mediaUploadImage,
				headers: {
					"Authorization": 'Bearer ' + localStorage.getItem('token')
				},
				uploadData: {
					media_type: 1,
					product_id: ''
				},
				fileList: [],
				details: '',
				ParameterFrom: {
					parameter: []
				},
				totalStocks: 0,
				skuData: {
					skuSpecAndDetailDTOS: []
				},
				SkuTableData: [],
				tableHead: [],
				arr: [],
				disShow: false,

				guigeVisible: false,
				dialogVisible: false,
				dialogImageUrl: '',
				action2: '/wsj/' + this.$api.mediaUploadImage,
				skuImgupload: {
					product_id: '',
					media_type: 2
				},
				imgIndex: '',
				SKufileList: [],
				mallDeductRate: 0,
				skuDataresult: [],
				skusData: [],
				categoryListData: [],
				categoryData: '',
				categoryDataProps: {
					value: 'id',
					label: 'name',
					children: 'childList',
					checkStrictly: true
				},
				skuImageId: '',
				skuPage: 1,
				skuSize: 10,
				skuTotal: 0,
				isUnlock: false,
				lockVisible: false,
				mallposition: {
					num: 1,
					password: '',
					mid: localStorage.getItem('merchantId')
				},
				mallpositionrules: {
					num: [{
						required: true,
						message: '请输入购买数量',
						trigger: 'blur'
					}],
					password: [{
						required: true,
						message: '请输入交易密码',
						trigger: 'blur'
					}],
				},
				goldenBeanPrice:0,
				goldNumber:0
			}
		},
		components: {
			editor
		},
		mounted() {
			this.queryData.business_id = localStorage.getItem('merchantId');
			this.getData();
			this.getMerchantList();
			this.getBrandList();
			this.getMallDeductRate();
			this.getGroup();
			this.getcategoryList();
			this.getIsUnlock();
		},
		methods: {
			alldown() {
				this.$confirm('是否下架所有商品?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$http.put(this.$api.oneUndercarriage, {
						mid: localStorage.getItem('merchantId')
					}).then(res => {
						if (res.code == 0) {
							this.$message({
								type: "success",
								message: '下架成功！'
							});
							this.getData();
						} else {
							this.$message.error(res.msg);
						}
					})
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消'
					});
				});
			},
			//撤销审核
			chexiao(row) {
				this.$confirm('是否撤销商品发布?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$http.put(this.$api.productUndo + '/' + row.id).then(res => {
						if (res.code == 0) {
							this.$message({
								type: "success",
								message: '撤销成功！'
							});
							this.getData();
						} else {
							this.$message.error(res.msg);
						}
					})
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消'
					});
				});

			},
			//解锁商品位
			unlockMallPosition(mallposition) {
				this.$refs[mallposition].validate((valid) => {
					if (valid) {
						this.$http.post(this.$api.positionBuy, this.mallposition).then(res => {
							if (res.code == 0) {
								this.$message({
									type: "success",
									message: '购买成功'
								});
								this.lockVisible = false;
								this.getIsUnlock();
							} else {
								this.$message.error(res.msg);
							}
						})
					} else {
						return false;
					}
				});
			},
			unlock() {
				this.mallposition = {
					num: 1,
					password: '',
					mid: localStorage.getItem('merchantId')
				};
				this.$http.get(this.$api.positionPrice).then(res => {
					if (res.code == 0) {
						this.lockVisible = true
					} else {
						this.$message.error(res.msg);
					}
				})

			},
			//判读是否需要解锁商品位
			getIsUnlock() {
				this.$http.get(this.$api.unlock, {
					mid: localStorage.getItem('merchantId')
				}).then(res => {
					this.isUnlock = res.data;
				})
			},
			tableRowClassName({
				row,
				rowIndex
			}) {
				if (row.totalStocks <= row.warnUnit) {
					return 'warning-row';
				}
			},
			tableRowClassName2({
				row,
				rowIndex
			}) {
				if (row.skuTotalStocks <= row.skuWarnUnit) {
					return 'warning-row';
				}
			},
			viewStocks(row) {
				this.stockActiveName = 'first',
					this.stockPage = 1;
				this.stockDialogVisible = true;
				this.stockProductId = row.productId;
				this.stockSkuId = row.id;
				this.getStockData();
			},
			stockHandleClick(tab) {
				if (tab.name == 'first') {
					this.getStockData();
				} else {
					this.getStockDataRecode();
				}
			},
			getStockData() {
				const loading = this.$loading({
					lock: true,
					text: 'Loading',
					spinner: 'el-icon-loading',
					background: 'rgba(0, 0, 0, 0.7)'
				});
				this.$http.get(this.$api.skuInventories, {
					product_id: this.stockProductId,
					sku_id: this.stockSkuId,
					page: this.stockPage,
					size: this.stockSize
				}).then(res => {
					loading.close();
					this.stockChangeData = res.data;
					this.stockTotal = res.extraInfo;
				})
			},
			getStockDataRecode() {
				const loading = this.$loading({
					lock: true,
					text: 'Loading',
					spinner: 'el-icon-loading',
					background: 'rgba(0, 0, 0, 0.7)'
				});
				this.$http.get(this.$api.skuInventoriesRecords, {
					product_id: this.stockProductId,
					sku_id: this.stockSkuId,
					page: this.stockPage,
					size: this.stockSize
				}).then(res => {
					loading.close();
					this.stockChangeData = res.data;
					this.stockTotal = res.extraInfo;
				})
			},
			StockHandleCurrentChange(val) {
				this.stockPage = val;
				if (this.stockActiveName == 'first') {
					this.getStockData();
				} else {
					this.getStockDataRecode();
				}
			},
			fabu(row) {
				this.$prompt('请输入消息内容', '发布', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
				}).then(({
					value
				}) => {
					this.$http.put(this.$api.mallSubmit, {
						id: row.id,
						verifyMsg: value
					}).then(res => {
						if (res.code == 0) {
							this.$message({
								type: 'success',
								message: '发布成功！等待平台审核'
							})
							this.getData();
						} else {
							this.$message.error('发布失败！' + res.msg);
						}
					})
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '取消输入'
					});
				});
			},
			getcategoryList() {
				this.$http.get(this.$api.categoryList).then(res => {
					this.categoryListData = this.getTreeData(res.data);
				})
			},
			getTreeData(data) {
				for (var i = 0; i < data.length; i++) {
					if (data[i].childList.length < 1) {
						// children若为空数组，则将children设为undefined
						data[i].childList = undefined;
					} else {
						// children若不为空数组，则继续 递归调用 本方法
						this.getTreeData(data[i].childList);
					}
				}
				return data;
			},
			search() {
				this.queryData.top_category_id = this.categoryData[0] ? this.categoryData[0] : ''
				this.queryData.product_category_id = this.categoryData[1] ? this.categoryData[1] : ''
				this.page = 1;
				this.getData();
			},
			sweetChange() {
				this.$http.post(this.$api.mallCalculate, {
					productSalePrice: this.stockData.skuSalePrice ? this.stockData.skuSalePrice : 0,
					sweetDeductRate: this.stockData.skuSweetDeductRate ? this.stockData.skuSweetDeductRate : 0,
				}).then(res => {
					if (res.code == 0) {
						this.skuSweetDeductRateData.salePrice = res.data.salePrice;
						this.skuSweetDeductRateData.saleSweet = res.data.saleSweet;
					} else {
						this.$message.error(res.msg);
					}

				})
			},
			submitStock() {
				this.stockData.productId = this.productId
				if (this.stockData.id) {
					this.$http.put(this.$api.skusingle, {
						productId: this.stockData.productId,
						"id": this.stockData.id,
						"skuCostPrice": this.stockData.skuCostPrice,
						"skuName": this.stockData.skuName,
						"skuOriginalPrice": this.stockData.skuOriginalPrice,
						"skuPicUrl": this.stockData.skuPicUrl,
						'skuMediaId': this.stockData.skuMediaId,
						"skuSalePrice": this.stockData.skuSalePrice,
						"skuSweetDeductRate": this.stockData.skuSweetDeductRate,
						"skuTotalStocks": this.stockData.skuTotalStocks,
						"skuWarnUnit": this.stockData.skuWarnUnit
					}).then(res => {
						if (res.code == 0) {
							this.$message({
								type: 'success',
								message: '修改成功！'
							});
							this.dialogStock = false;
							this.skuInfo();
							this.getData();
						} else {
							this.$message({
								type: 'success',
								message: '修改失败！' + res.msg
							})
						}
					})
				} else {
					this.$http.post(this.$api.skusingleAdd, this.stockData).then(res => {
						if (res.code == 0) {
							this.$message({
								type: 'success',
								message: '新增成功！'
							});
							this.dialogStock = false;
							this.getData();
							this.skuInfo();
						} else {
							this.$message({
								type: 'success',
								message: '新增失败！' + res.msg
							})
						}
					})
				}
			},
			addStock(row) {
				//编辑
				if (row != undefined) {
					this.skuActive = false;
					this.dialogStock = true;
					this.stockData = row;
					this.sweetChange();
				} else {
					//添加
					this.$http.get(this.$api.mallSpec, {
						product_id: this.productId,
					}).then(res => {
						if (res.data.length == 0) {
							this.$message.error('请先添加规格！');
							return false;
						} else {
							this.skuActive = true;
							this.dialogStock = true;
							this.guigeData = res.data;
						}
					});
					this.skuSweetDeductRateData = {
						salePrice: 0,
						saleSweet: 0,
						mallDeductRates: 40
					};
					this.stockData = {
						specDetailMap: {},
						skuName: this.form.productName,
						extId: '',
						limitNum: '',
						skuSalePrice: this.form.productSalePrice,
						skuSweetDeductRate: this.form.sweetDeductRate,
						skuCostPrice: this.form.productCostPrice,
						skuTotalStocks: '',
						skuWarnUnit: '',
						skuPicUrl: '',
						skuMediaId: '',
					}
					this.sweetChange();
					this.stockArr = {};
				}

			},
			skuChange(item, name) {
				this.stockArr[name] = item;
			},
			deleteSku(index, row) {
				this.$confirm('此操作将永久删除该条SKU, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$http.delete(this.$api.delSku + '/' + row.id).then(res => {
						if (res.code == 0) {
							this.$message({
								type: 'success',
								message: '删除成功！'
							});
							this.skuInfo();
						} else {
							this.$message.error('删除失败！' + res.msg);
						}
					})
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消删除'
					});
				});

			},
			//添加规格
			addSpecs() {
				this.dialogSpecs = true;
				this.getSpecs();
			},
			addguige() {
				if (this.guigeFormData.guige.trim() == '') {
					this.$message.error('规格不能为空！');
					return
				}
				this.$http.post(this.$api.mallSpec, {
					productId: this.productId,
					specName: this.guigeFormData.guige.trim()
				}).then(res => {
					if (res.code == 0) {
						this.$message({
							type: 'success',
							message: '添加成功！'
						})
						this.guigeFormData.guige = '';
						this.getSpecs();
					} else {
						this.$message.error('添加失败！' + res.msg);
					}
				})
			},
			getSpecs() {
				this.$http.get(this.$api.mallSpec, {
					product_id: this.productId,
				}).then(res => {
					this.guigeData = res.data;
				})
			},
			append(data) {
				this.$prompt('请输入规格详情', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消'
				}).then(({
					value
				}) => {
					if (value == null) {
						this.$message.error('规格详情不能为空！');
						return
					}
					this.$http.post(this.$api.detail, {
						productSpecId: data.id,
						specDetailName: value.trim()
					}).then(res => {
						if (res.code == 0) {
							this.$message({
								type: 'success',
								message: '添加成功！'
							});
							this.getSpecs();
						} else {
							this.$message({
								type: 'error',
								message: '添加失败！' + res.msg
							})
						}

					})
				});
			},
			modify(node, data) {
				if (data.specDetails) {
					this.$prompt('规格', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						inputValue: data.specName.trim()
					}).then(({
						value
					}) => {
						if (value == '') {
							this.$message.error('规格不能为空！');
							return
						}
						this.$http.put(this.$api.mallSpec, {
							id: data.id,
							productId: data.productId,
							specName: value.trim()
						}).then(res => {
							if (res.code == 0) {
								this.$message({
									type: 'success',
									message: '修改成功！'
								});
								this.getSpecs();
							} else {
								this.$message({
									type: 'error',
									message: '修改失败！' + res.msg
								})
							}
						})
					});

				} else {
					this.$prompt('规格详情', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						inputValue: data.specDetailName.trim()
					}).then(({
						value
					}) => {
						if (value == '') {
							this.$message.error('规格详情不能为空！');
							return
						}
						this.$http.put(this.$api.detail, {
							id: data.id,
							productSpecId: data.productSpecId,
							specDetailName: value.trim()
						}).then(res => {
							if (res.code == 0) {
								this.$message({
									type: 'success',
									message: '修改成功！'
								});
								this.getSpecs();
							} else {
								this.$message({
									type: 'error',
									message: '修改失败！' + res.msg
								})
							}
						})
					});

				}
			},
			remove(node, data) {
				if (data.specDetails) {
					this.$confirm('此操作将删除该规格, 是否继续?', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then(() => {
						this.$http.delete(this.$api.mallSpec + '/' + data.id).then(res => {
							if (res.code == 0) {
								this.$message({
									type: "success",
									message: '删除成功！'
								});
								this.getSpecs();
							} else {
								this.$message({
									type: "error",
									message: '删除失败！' + res.msg
								})
							}
						})
					}).catch(() => {
						this.$message({
							type: 'info',
							message: '已取消删除'
						});
					});
				} else {
					this.$confirm('此操作将删除该规格, 是否继续?', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then(() => {
						this.$http.delete(this.$api.detail + '/' + data.id).then(res => {
							if (res.code == 0) {
								this.$message({
									type: "success",
									message: '删除成功！'
								});
								this.getSpecs();
							} else {
								this.$message({
									type: "error",
									message: '删除失败！' + res.msg
								})
							}
						})
					}).catch(() => {
						this.$message({
							type: 'info',
							message: '已取消删除'
						});
					});
				}
			},
			tabHandleClick(tab) {
				if (tab.index == 0 && this.title == '编辑商品') {
					this.getMallInfo();
				} else if (tab.index == 1 && this.title == '编辑商品') {
					this.mediaInfo();
				} else if (tab.index == 2 && this.title == '编辑商品') {
					this.attrValueInfo();
				} else if (tab.index == 3 && this.title == '编辑商品') {
					this.skuInfo();
				}
			},
			changeFenZu(row) {
				let str = ''
				if (row != null) {
					row.forEach(item => {
						str += item.title + ','
					});
					return '[' + str.substr(0, str.length - 1) + ']';
				} else {
					return ''
				}
			},
			//设置分组
			setGroup(row) {
				this.fenzu = []
				this.fenzudialogVisible = true;
				this.productId = row.id;
				if (row.groups != null) {
					row.groups.forEach(item => {
						this.fenzu.push(item.id);
					})
				} else {
					this.fenzu = []
				}
			},
			//获取分组列表
			getGroup() {
				this.$http.get(this.$api.productGroupList).then(res => {
					res.data.forEach(item => {
						this.fenZuData.push({
							key: item.id,
							label: item.title,
							disabled: false
						})
					})
				})
			},
			//提交分组
			fenZuSubmit() {
				this.$http.put(this.$api.productGroupProducts, {
					groupIds: this.fenzu,
					productId: this.productId
				}).then(res => {
					if (res.code == 0) {
						this.$message({
							type: 'success',
							message: '设置成功！'
						})
						this.fenzudialogVisible = false;
						this.getData();
					} else {
						this.$message({
							type: 'error',
							message: '设置失败,' + res.msg
						})
					}
				})
			},
			//商家切换
			mechantChange(val) {
				this.getShipping(val);
			},
			//计算返回商品当天实时参考价格
			sweetDeductRateChange() {
				if (this.form.productSalePrice && this.form.sweetDeductRate >= 0) {
					this.$http.post(this.$api.mallCalculate, {
						productSalePrice: this.form.productSalePrice,
						sweetDeductRate: this.form.sweetDeductRate,
					}).then(res => {
						if (res.code == 0) {
							this.cankaoPrice = res.data
						} else {
							this.cankaoPrice = {};
							this.$alert(res.msg)
						}
					})
				}
			},
			//计算返回商品当天SKU实时参考价格
			skuSweetDeductPriceChange(index, row) {
				if (row.skuSalePrice && row.skuSweetDeductRate) {
					this.$http.post(this.$api.mallCalculate, {
						productSalePrice: row.skuSalePrice,
						sweetDeductRate: row.skuSweetDeductRate,
					}).then(res => {
						if (res.code == 0) {
							this.SkuTableData[index].salePrice = res.data.salePrice;
							this.SkuTableData[index].saleSweet = res.data.saleSweet;
						} else {
							this.cankaoPrice = {};
							this.$alert(res.msg)
						}
					})
				}
			},
			getMallDeductRate() {
				this.$http.get(this.$api.mallDeductRate).then(res => {
					this.mallDeductRate = res.data;
				})
			},
			productSalePriceChange() {
				this.sweetDeductRateChange();
				this.jindouRateChange();
			},
			//计算金豆当天实时参考价格
			jindouRateChange() {
			  if (this.form.productSalePrice) {
			    this.$http.get(this.$api.getGoldenBeanPrice, {
			      price: this.form.productSalePrice
			    }).then(res => {
			      if (res.code == 0) {
			        this.goldenBeanPrice = res.data.goldenBeanPrice;
			        this.goldNumber = res.data.number;
			      }
			    })
			  }
			},
			getData() {
				this.$http.get(this.$api.mallList, this.queryData).then(res => {
					this.tableData = res.data;
					this.total = res.extraInfo;
				})
			},
			handleCurrentChange(val) {
				this.queryData.page = val;
				this.getData();
			},
			//商品类型切换
			radioChange(val) {
				this.$refs.form.clearValidate();
				this.form = {
					productType: val, //商品类型
					createUserId: this.$store.state.user.userId, //用户ID
					mid: Number(localStorage.getItem('merchantId')), //商家id
					expireTime: '', //商品订单过期时间(单位:分钟)
					isDeliveryCityEnabled: false, //同城配送
					isDeliveryExpressEnabled: false, //快递配送
					isDeliveryPickEnabled: false, //到店自提
					productBrandId: '', //商品品牌id
					productCategoryId: '', //商品类目id
					productCostPrice: '', //商品成本价
					productDeliveryId: '', //同城配送模版id
					productDesc: '', //兑换须知
					productFreightId: '', //运费模板id
					productName: '', //商品名称
					productSalePrice: '', //商品销售价
					productTitle: '', //商品副标题
					productWeight: 0, //商品重量
					sweetDeductRate: 0, //糖果抵扣率
					warnUnit: '', //预警数量
					type: 0,
					limitNum: 0, //限购数量
					limitTimes: 0, //限购次数
					isUseCoupon: true, //是否可使用优惠券购买
					goldenBeansStatus:1
				}

				if (this.form.id) {
					this.form.productType = val;
				}

			},
			//商品审核
			check(row) {
				this.verify = true;
				this.verifyForm.id = row.id;
			},
			//商品审核提交
			onSubmit() {
				this.$http.put(this.$api.mallVerifyStatus, this.verifyForm).then(res => {
					if (res.code == 0) {
						this.$message({
							type: 'success',
							message: '审核成功！'
						})
						this.getData();
						this.verify = false;
					} else {
						this.$message.error('审核失败！')
					}
				})
			},
			//图片上传校验
			beforeUpload(file) {
				const isSize = new Promise(function(resolve, reject) {
					const _URL = window.URL || window.webkitURL
					const img = new Image()
					img.onload = function() {
						const valid = img.width === img.height && (img.width >= 720 || img.width <= 1080)
						valid ? resolve() : reject(new Error('error'))
					}
					img.src = _URL.createObjectURL(file)
				}).then(() => {
					return file
				}, () => {
					this.$message.error('图片尺寸规格必须为720*720，图片背景要求非白色，左上角不能放文字/logo，否则审核不通过')
					return Promise.reject(new Error('error'))
				});
				return isSize
			},
			//上/下架
			xiajia(row) {
				let product_status = (row.productStatus == 4 || row.productStatus == 2) ? 5 : row.productStatus == 5 ? 4 :
					'';
				let name = (row.product_status == 4 || row.productStatus == 2) ? '下架' : row.product_status == 5 ? '上架' :
					'';
				this.$http.put(this.$api.mallStatus, {
					id: row.id,
					productStatus: product_status
				}).then(res => {
					if (res.code == 0) {
						this.$message({
							type: "success",
							message: name + '成功！'
						})
						this.getData();
					} else {
						this.$message.error(name + '失败！' + res.msg);
					}
				})
			},
			//商家列表
			getMerchantList() {
				this.$http.get(this.$api.merchantSimple, {
					query: ''
				}).then(res => {
					this.restaurants = res.data;
				})
			},
			//商品品牌列表
			getBrandList() {
				this.$http.get(this.$api.brandList, {
					page: 1,
					size: 100
				}).then(res => {
					this.brandListData = res.data;
				})
			},
			//获取运费模版
			getShipping(val) {
				this.$http.get(this.$api.transportQuery, {
					productId: val,
				}).then(res => {
					this.shippingData = res.data;
				})
			},
			addMall() {
				this.$refs.form.clearValidate();
				this.title = '添加商品';
				this.mallVisible = true;
				this.progress = 0;
				this.activeName = '1';
				this.details = '';
				this.ParameterFrom = {
					parameter: []
				};
				this.getShipping(localStorage.getItem('merchantId'));
				//this.getSameCityDelivery(localStorage.getItem('merchantId'));
				this.form = {
						productType: 1, //商品类型
						createUserId: localStorage.getItem('merchantId'), //用户ID
						mid: Number(localStorage.getItem('merchantId')), //商家id
						expireTime: '', //商品订单过期时间(单位:分钟)
						isDeliveryCityEnabled: false, //同城配送
						isDeliveryExpressEnabled: false, //快递配送
						isDeliveryPickEnabled: false, //到店自提
						productBrandId: '', //商品品牌id
						productCategoryId: '', //商品类目id
						productCostPrice: '', //商品成本价
						productDeliveryId: '', //同城配送模版id
						productDesc: '', //兑换须知
						productFreightId: '', //运费模板id
						productName: '', //商品名称
						productSalePrice: '', //商品销售价
						productTitle: '', //商品副标题
						productWeight: 0, //商品重量
						sweetDeductRate: 0, //糖果抵扣���
						warnUnit: '', //预警数量
						type: 0,
						limitNum: 0, //限购数量
						limitTimes: 0, //限购次数
						isUseCoupon: true, //是否可使用优惠券购买
						goldenBeansStatus:1
					},
					this.fileList = [];
			},
			removeSku(index, row) {
				if (row.id) {
					this.$http.delete(this.$api.delSku).then(res => {
						if (res.code == 0) {
							this.$message({
								type: 'success',
								message: '删除成功！'
							})
							this.SkuTableData.splice(index, 1);
						} else {
							this.$message.error('删除失败！');
						}
					})
				} else {
					this.$message({
						type: 'success',
						message: '删除成功！'
					});
					this.SkuTableData.splice(index, 1);
				}
			},
			//删除商品
			mallDelete(row) {
				this.$confirm('此操作将永久删除该商品, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$http.delete(this.$api.mallDelete + '/' + row.id).then(res => {
						if (res.code == 0) {
							this.$message({
								type: 'success',
								message: '删除成功!'
							});
							this.getData();
						} else {
							this.$message({
								type: 'error',
								message: '删除失败,' + res.msg
							});
						}
					})
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消删除'
					});
				});
			},
			//编辑商品，获取商品基本信息
			mallUpdate(row) {
				this.progress = 4;
				this.form = {};
				this.productId = row.id;
				this.uploadData.product_id = row.id;
				this.activeName = '1';
				this.getMallInfo();
				this.getShipping(row.mid);
			},
			getMallInfo() {
				this.$http.get(this.$api.ProductInfo + '/' + this.productId).then(res => {
					this.title = '编辑商品';
					this.mallVisible = true;
					this.form = res.data;
					this.cankaoPrice = {
						salePrice: res.data.salePrice,
						saleSweet: res.data.saleSweet
					}
				})
			},
			//平台获取商品基本信息
			mediaInfo() {
				if (!this.productId) {
					return
				}
				this.fileList = [];
				this.details = '';
				this.$http.get(this.$api.mediaInfo + '/' + this.productId).then(res => {
					res.data.mediaMains.forEach(item => {
						this.fileList.push({
							url: item.productMediaUrl,
							id: item.id,
							sort: item.sort
						})
					})
					this.details = res.data.details == null ? '' : res.data.details;
					this.introduction = res.data.details;
				})
			},
			//平台获取商品参数信息
			attrValueInfo() {
				this.$http.get(this.$api.attrValueInfo + '/' + this.productId).then(res => {
					this.ParameterFrom.parameter = res.data.productAttrValues;
				})
			},
			//平台获取商品SKU信息
			skuInfo() {
				this.$http.get(this.$api.skuInfo, {
					page: this.skuPage,
					size: this.skuSize,
					product_id: this.productId
				}).then(res => {
					this.skusData = this.skuDataresult = res.data;
					this.skuTotal = res.extraInfo
				})
			},
			//sku分页
			skuHandleCurrentChange(val) {
				this.skuPage = val;
				this.skuInfo();
			},
			chazhao() {
				this.leimuVisible = true;
				this.$http.get(this.$api.categoryList).then(res => {
					this.category[0].childList = res.data
				})
			},
			choice(data, node) {
				this.form.productCategoryId = node.id
				this.form.productCategoryName = node.name;
				this.leimuVisible = false;
			},
			submit(from) {
				this.fileList = [];
				this.details = '';
				this.$refs[from].validate((valid) => {
					if (valid) {
						if (this.form.productType == 1) {
							if (!this.form.isDeliveryCityEnabled && !this.form.isDeliveryExpressEnabled && !this
								.form.isDeliveryPickEnabled) {
								this.$alert('必须选择至少一种配送方式！');
								return false
							} else {
								if (this.form.isDeliveryExpressEnabled && !this.form.productFreightId) {
									this.$alert('请选择快递配送模板！');
									return false
								}
							}
						}
						if (this.form.id) {
							this.$http.put(this.$api.mallUpdate, this.form).then(res => {
								if (res.code == 0) {
									this.$http.put(this.$api.mallProgress, {
										id: this.form.id,
										progress: this.progress
									}).then(res => {
										if (res.code == 0) {
											this.$message({
												type: 'success',
												message: '修改成功！'
											})
											this.mallImage = false;
											this.activeName = '2';
											this.mediaInfo();
											this.getData();
										} else {
											this.$message.error('修改失败,' + res.msg);
										}
									})
								} else {
									this.$message.error('修改失败,' + res.msg);
								}
							})
						} else {
							this.$http.post(this.$api.mallAdd, this.form).then(res => {
								if (res.code == 0) {
									this.productId = res.data;
									this.form.id = res.data;
									this.uploadData.product_id = res.data;
									this.$http.put(this.$api.mallProgress, {
										id: res.data,
										progress: 1
									}).then(res => {
										if (res.code == 0) {
											this.$message({
												type: 'success',
												message: '保存成功！'
											})
											this.mallImage = false;
											this.activeName = '2';
											this.progress = 1;
											this.getData();
										} else {
											this.$message.error('保存失败,' + res.msg);
										}
									})
								} else {
									this.$message.error('保存失败,' + res.msg);
								}
							})
						}
					} else {
						return false;
					}
				});
			},
			handleSuccess(res, file, fileList) {
				if (res.code == 0) {
					// this.fileList = fileList;
					this.fileList.push({
						url: file.url,
						id: file.response.data.id,
						sort: file.response.data.sort
					})
				} else {
					fileList.splice(fileList.length - 1, 1);
					this.$message.error('上传失败！' + res.msg);
				}
			},
			changeCardSort(val, file) {
				let fileIndex = this.fileList.findIndex(item => item.id == file.id)
				if (fileIndex != -1) {
					this.fileList[fileIndex].sort = val
				}
			},
			submitCardSort() {
				let ids = this.fileList.reduce((acc, cur) => {
					acc.push({
						id: cur.id,
						sort: cur.sort
					})
					return acc
				}, [])
				// 修改排序接口
				this.$http.put(this.$api.mediaSort, ids).then(res => {
					if (res.code == 0) {
						this.$message({
							type: 'success',
							message: '排序成功'
						});
						this.mediaInfo()
					} else {
						this.$message.error('排序失败,' + res.msg)
					}
				})
			},
			beforeRemove() {
				return false
			},
			// 下载图片
			handleDownload(file) {
				window.location.href = file.url
			},
			//删除
			handleRemove(file) {
				let id = file.id || file.response.data.id
				this.$http.delete(this.$api.mediaDelete + '/' + id).then(res => {
					if (res.code == 0) {
						this.$message({
							type: 'success',
							message: '删除成功'
						});
						// this.fileList = fileList;
						this.fileList = this.fileList.filter(item => {
							return item.id != id
						});
					} else {
						this.$message.error('删除失败,' + res.msg)
					}
				})
			},
			SkuHandleRemove(file) {
				this.SKufileList = [];
			},
			catchData(val) {
				this.introduction = val;
			},
			ImgSubmit() {
				/* if (this.fileList.length == 0) {
					this.$message({
						type: 'error',
						message: '请上传商品Banner图片'
					});
					return false
				} */

				if (!this.introduction) {
					this.$message({
						type: 'error',
						message: '请上传商品详情'
					});
					return false
				}
				this.$http.put(this.$api.productDetails, {
					id: this.productId,
					details: this.introduction
				}).then(res => {
					if (res.code == 0) {
						this.$http.put(this.$api.mallProgress, {
							id: this.productId,
							progress: 2
						}).then(res => {
							if (res.code == 0) {
								this.$message({
									type: 'success',
									message: '保存成功！'
								})
								this.activeName = '3';
								this.progress = 2;
								this.attrValueInfo();
								this.getData();
							} else {
								this.$message.error('保存失败,' + res.msg);
							}
						})
					} else {
						this.$message.error('保存失败,' + res.msg);
					}
				})
			},
			//添加参数
			addParameter() {
				this.ParameterFrom.parameter.push({
					productAttrName: '',
					productAttrValue: '',
					productId: this.productId
				})
			},
			removeParameter(item) {
				if (item.id) {
					this.$http.delete(this.$api.batchDelete + '/' + item.id).then(res => {
						if (res.code == 0) {
							var index = this.ParameterFrom.parameter.indexOf(item);
							if (index !== -1) {
								this.ParameterFrom.parameter.splice(index, 1)
							}
							this.$message({
								type: "success",
								message: '删除成功！'
							});
						} else {
							this.$message.error('删除失败,' + res.msg);
						}
					})
				} else {
					var index = this.ParameterFrom.parameter.indexOf(item);
					if (index !== -1) {
						this.ParameterFrom.parameter.splice(index, 1)
					}
				}
			},
			//
			ParameterSubmit() {
				if (this.ParameterFrom.parameter.length > 0) {
					this.$http.put(this.$api.productAttrValue, this.ParameterFrom.parameter).then(res => {
						if (res.code == 0) {
							this.$http.put(this.$api.mallProgress, {
								id: this.productId,
								progress: 3
							}).then(res => {
								if (res.code == 0) {
									this.$message({
										type: 'success',
										message: '修改成功！'
									})
									this.activeName = '4';
									this.progress = 3;
									this.skuInfo();
									this.getData();
								} else {
									this.$message.error('修改失败，' + res.msg);
								}
							})

						} else {
							this.$message.error('修改失败，' + res.msg);
						}
					})
				} else {
					this.$http.post(this.$api.productAttrValue, this.ParameterFrom.parameter).then(res => {
						if (res.code == 0) {
							this.$http.put(this.$api.mallProgress, {
								id: this.uploadData.product_id,
								progress: 3
							}).then(res => {
								if (res.code == 0) {
									this.$message({
										type: 'success',
										message: '保存成功！'
									})
									this.activeName = '4';
									this.progress = 3;
									this.getData();
								} else {
									this.$message.error(res.msg);
								}
							})
						} else {
							this.$message.error(res.msg);
						}
					})
				}
			},
			//添加规格
			addSku() {
				this.skuData.skuSpecAndDetailDTOS.push({
					specName: '',
					specDetails: [{
						specDetailName: ''
					}]
				})
			},
			//删除规格
			skuDelete(index) {
				this.skuData.skuSpecAndDetailDTOS.splice(index, 1);
			},
			//添加规格值
			addSpecDetail(index) {
				this.skuData.skuSpecAndDetailDTOS[index].specDetails.push({
					specDetailName: ''
				})
			},
			//删除规格值
			iconDelete(index, index2) {
				this.skuData.skuSpecAndDetailDTOS[index].specDetails.splice(index2, 1);
			},
			multiCartesian(specs) {
				// 判断是否传递了参数，是否是空数组
				if (!specs || specs.length == 0) {
					return [];
				} else {
					return joinSpec([
						[]
					], specs, 0, specs.length - 1);
				}

				// prevProducts 和 specs 两个数组做笛卡尔积
				// i 是索引，表示原始数组遍历的位数
				// max 是原始数组最大的长度
				function joinSpec(prevProducts, specs, i, max) {
					var currentProducts = [],
						currentProduct, currentSpecs = specs[i];
					if (i > max) {
						return prevProducts;
					}
					// 前面的数组 和 紧跟着后面的数组 做笛卡尔积
					prevProducts.forEach(function(prevProduct, index) {
						currentSpecs.forEach(function(spec) {
							currentProduct = prevProduct.slice(0);
							currentProduct.push(spec);
							currentProducts.push(currentProduct);
						});
					});
					// 递归处理，前面笛卡尔积之后的结果作为前面的数组，然后循环往前推进1位
					return joinSpec(currentProducts, specs, ++i, max);
				}
			},
			skuSubmit() {
				this.tableHead = [];
				this.SkuTableData = [];
				let arr = [];
				var obj = {};
				var guige = [];
				var data = this.skuDataresult;
				this.skuData.skuSpecAndDetailDTOS.forEach((item, index) => {
					if (item.id) {
						this.tableHead.push({
							id: item.id,
							label: item.specName,
							property: `specDetailName${index}`
						});
					} else {
						this.tableHead.push({
							label: item.specName,
							property: `specDetailName${index}`
						});
					}
					arr.push(item.specDetails);
				});

				this.$http.post(this.$api.mallCalculate, {
					productSalePrice: this.form.productSalePrice,
					sweetDeductRate: this.form.sweetDeductRate,
				}).then(response => {
					if (response.code == 0) {
						var _this = this;
						this.multiCartesian(arr).forEach((res, index) => {
							if (this.form.productType == 1) {
								obj = {
									skuName: this.form.productName, //sku名称
									isDeleted: false,
									skuCostPrice: this.form.productCostPrice, //sku成本价
									skuSalePrice: this.form.productSalePrice, //sku销售价
									salePrice: response.data.salePrice,
									saleSweet: response.data.saleSweet,
									skuSweetDeductRate: this.form.sweetDeductRate, //sku糖果抵扣率
									skuPicUrl: '', //sku图片url
									skuMediaId: '',
									skuTotalStocks: '', //sku库存
									skuWarnUnit: '' //sku库存预警数量
								};
							} else {
								obj = {
									skuName: this.form.productName, //sku名称
									isDeleted: false,
									skuCostPrice: this.form.productCostPrice, //sku成本价
									skuSalePrice: this.form.productSalePrice, //sku销售价
									salePrice: response.data.salePrice,
									saleSweet: response.data.saleSweet,
									extId: 0,
									limitNum: 0,
									skuSweetDeductRate: this.form.sweetDeductRate, //sku糖果抵扣率
									skuPicUrl: '', //sku图片url
									skuMediaId: '',
									skuTotalStocks: '', //sku库存
									skuWarnUnit: '', //sku库存预警数量
								}
							}
							res.forEach((item, subIndex) => {
								obj['specDetailName' + subIndex] = item.specDetailName;
							});
							this.SkuTableData.push(obj);
						});
					}
				})

			},
			baocunSku() {
				var obj = {};
				var result = []
				try {
					this.SkuTableData.forEach((res, index) => {
						if (!res.skuName) {
							this.$message.error(`第${index+1}条名称不能为空！`);
							throw new Error(`第${index+1}条名称不能为空！`);
						}
						/* if (!res.skuCostPrice) {
							this.$message.error(`第${index+1}条成本价不能为空！`);
							throw new Error(`第${index+1}条成本价不能为空！`);
						}

						if (!res.skuSalePrice) {
							this.$message.error(`第${index+1}条销售价不能为空！`);
							throw new Error(`第${index+1}条销售价不能为空！`);
						} */

						/* if (!res.skuSweetDeductRate) {
							this.$message.error(`第${index+1}条糖果抵扣率不能为空！`);
							throw new Error(`第${index+1}条糖果抵扣价不能为空！`);
						} */
						if (!res.skuPicUrl) {
							this.$message.error(`第${index+1}条图片不能为空！`);
							throw new Error(`第${index+1}条图片不能为空！`);
						}
						if (!res.skuTotalStocks) {
							this.$message.error(`第${index+1}条库存不能为空！`);
							throw new Error(`第${index+1}条库存不能为空！`);
						}

						/* if (!res.skuWarnUnit) {
							this.$message.error(`第${index+1}条库存预警数量不能为空！`);
							throw new Error(`第${index+1}条库存预警数量不能为空！`);
						} */
						obj.id = res.id;
						obj.isDeleted = res.isDeleted;
						obj.skuName = res.skuName; //sku名称
						obj.skuCostPrice = res.skuCostPrice; //sku成本价
						obj.skuSalePrice = res.skuSalePrice; //sku销售价
						obj.skuSweetDeductRate = res.skuSweetDeductRate; //sku糖果抵扣率
						obj.skuPicUrl = res.skuPicUrl; //sku图片url
						obj.skuMediaId = res.skuMediaId; //sku图片url
						obj.skuTotalStocks = res.skuTotalStocks; //sku库存
						obj.skuWarnUnit = res.skuWarnUnit; //sku库存预警数量
						obj.specDetails = [];
						this.tableHead.forEach((item, headIndex) => {
							if (item.id) {
								obj.specDetails.push({
									id: item.id,
									specName: item.label,
									specDetailName: res['specDetailName' + headIndex]
								})
							} else {
								obj.specDetails.push({
									specName: item.label,
									specDetailName: res['specDetailName' + headIndex]
								})
							}

						})
						result.push(obj);
						obj = {}
					})
				} catch (e) {
					if (e.message !== "LoopTerminates") throw e;
				};
				this.$http.post(this.$api.skuAdd, {
					productId: this.productId,
					isSkuEnabled: true,
					productSkuList: result
				}).then(res => {
					if (res.code == 0) {
						this.$message({
							type: 'success',
							message: '保存成功！'
						});
						this.SkuTableData = [];
						this.tableHead = [];
						this.skuData.skuSpecAndDetailDTOS = [];
						this.getData();
						this.mallVisible = false;
					} else {
						this.$message.error('保存失败,' + res.msg);
					}
				})
			},
			delImage(id) {
				this.$http.delete(this.$api.mediaDelete + '/' + id).then(res => {

				})
			},
			addSkuImages(row) {
				this.skuImgupload.product_id = this.productId;
				if (row.skuPicUrl) {
					this.SKufileList = []
					this.SKufileList.push({
						url: row.skuPicUrl,
					})
				} else {
					this.SKufileList = []
				}
				this.dialogImageUrl = row.skuPicUrl
				this.guigeVisible = true;
			},
			addSkuImage(index, row) {
				this.skuImgupload.product_id = this.productId;
				if (row[index].skuPicUrl) {
					this.SKufileList = []
					this.SKufileList.push({
						url: row[index].skuPicUrl
					})
				} else {
					this.SKufileList = []
				}
				this.dialogImageUrl = row[index].skuPicUrl
				this.imgIndex = index;
				this.guigeVisible = true;
			},
			handlePictureCardPreview(file) {
				this.dialogImageUrl = file.url;
				this.dialogVisible = true;
			},
			skuSuccessHandle(res) {
				if (this.title == '添加商品') {
					this.SkuTableData[this.imgIndex].skuPicUrl = res.data.productMediaUrl;
					this.SkuTableData[this.imgIndex].skuMediaId = res.data.id;
				} else {
					this.stockData.skuPicUrl = res.data.productMediaUrl;
					this.stockData.skuMediaId = res.data.id;
				}
				this.guigeVisible = false;
			},
			// 解锁商品位
			openLock() {
				this.$confirm('请前往套餐服务解锁更多商品位', '温馨提示', {
					confirmButtonText: '前往',
					// cancelButtonText: '取消',
				}).then(() => {
					this.$router.push('combo')
				}).catch(() => {
					// this.$message({
					// 	type: 'info',
					// 	message: '已取消删除'
					// });          
				});
			}
		}
	}
</script>
<style>
	.custom-class .el-dialog__header {
		border-bottom: 1px solid #ccc;
	}

	.custom-class .el-tree-node__content {
		height: 35px;
	}
</style>
<style scoped>
	.product-card>>>.el-upload-list--picture-card .el-upload-list__item {
		border: 0;
		height: 189px;
	}

	.mallList {
		padding: 15px;
	}

	.pages {
		display: flex;
		justify-content: center;
		margin: 30px 0;
	}

	.mall-box {
		display: flex;
	}

	.mall-box-del {
		display: flex;
		flex-direction: column;
		padding-left: 8px;
		justify-content: space-around;
	}

	.mall-name {
		font-size: 14px;
		text-align: left;
		color: #000;
	}

	.mall-title {
		text-align: left;
		font-size: 12px;
		color: #888;
	}

	.custom {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}


	.Category>>>.el-tree-node__expand-icon.is-leaf {
		color: transparent;
	}

	.Category>>>.el-tree-node__expand-icon {
		color: #000;
	}

	.custom-tree-node {
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-size: 14px;
		padding-right: 8px;
	}

	.mallList>>>.warning-row {
		background: #ffe9e9;
	}
</style>
